Skip to content

bpo-43574: Dont overallocate list literals#24954

Closed
chadnetzer wants to merge 11 commits intopython:mainfrom
chadnetzer:bpo43574-dont-overallocate-list-literals
Closed

bpo-43574: Dont overallocate list literals#24954
chadnetzer wants to merge 11 commits intopython:mainfrom
chadnetzer:bpo43574-dont-overallocate-list-literals

Conversation

@chadnetzer
Copy link

@chadnetzer chadnetzer commented Mar 21, 2021

Before v3.9, list literals weren't over-allocated, but this behavior regressed starting with v3.9:

Switched to initializing list literals w/ LIST_EXTEND
https://bugs.python.org/issue39320
#17984

Commit where over-allocation of list literals first appeared
https://bugs.python.org/issue38328
#17114
6dd9b64

This changes to the original behavior of not over-allocating lists for list literals, by not over-allocating any 0-length list that is extended. Technically this is a change in behavior, as lists that are initialized to length 0, and then immediately extended, will not be over-allocated on that initial extension. This change in behavior is likely innocuous, and possibly desirable, whereas the long-standing Python behavior of not using over-allocation for list literals is almost certainly desired.

Adds a test_overallocation test for lists to find regressions (assuming the regression doesn't alter the behavior of both the list-literal and list-initialization from a known length).

https://bugs.python.org/issue43574

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes needs backport to 3.10 only security fixes performance Performance or resource usage stale Stale PR or inactive for long period of time. type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants